package com.yanqu.road.server.cmd.marriage.crossworld;

import com.yanqu.road.entity.marriage.MarriageInfo;
import com.yanqu.road.logic.pb.MarriagePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.marriage.CrossMarriageProto;
import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.marriage.CrossUnionWorldMarriageMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.C_CROSS_WORLD_MARRIAGE_APPLY_PUBLISH_UPLOAD, desc = "发布全服联姻(上报)")
public class CrossWorldMarriagePublishUploadCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        CrossMarriageProto.CrossMarriageUploadServerPublishMsg uploadMsg = CrossMarriageProto.CrossMarriageUploadServerPublishMsg.parseFrom(packet.getBytes());
        List<MarriageInfo> marriageInfoList = new ArrayList<>(uploadMsg.getApplyCount());
        for (MarriageProto.MarriageApplyTempMsg tempMsg : uploadMsg.getApplyList()) {
            MarriageInfo marriageInfo = MarriagePb.parseMarriageInfo(tempMsg);
            marriageInfoList.add(marriageInfo);
        }

        CrossUnionWorldMarriageMgr.upload(serverId, marriageInfoList);
    }

    @Override
    public void sendData() {

    }
}
